package artid.com.arttogo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.PhotoInquiryList;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.network.BitmapCache;
import artid.com.arttogo.task.CallbackSky;

public class PhotoInquiryAdapter extends BaseAdapter {
	private Context mContext;
	LayoutInflater mInflater;
	ViewHolder holder;
	CallbackSky cs;
	public List<PhotoInquiryList> listdata;
	private ImageLoader mImageLoader;
	public PhotoInquiryAdapter(Context mContext) {
		this.mContext = mContext;
		mInflater = LayoutInflater.from(mContext);
		RequestQueue mQueue = Volley.newRequestQueue(mContext);
		mImageLoader = new ImageLoader(mQueue, new BitmapCache());
		
	}

	@Override
	public int getCount() {
		return listdata.size();
	}


	public void adddata(List<PhotoInquiryList> listdata) {
		this.listdata.addAll(listdata);
		notifyDataSetChanged();
	}
	public void setdata(List<PhotoInquiryList> listdata) {
		this.listdata = listdata;
		notifyDataSetChanged();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_camera_result, null);
			vh.title = (TextView) convertView
					.findViewById(R.id.text_artname_camera_result);
			vh.author = (TextView) convertView
					.findViewById(R.id.text_artistname_camera_result);
			vh.iv = (ImageView) convertView
					.findViewById(R.id.img_camera_result);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		PhotoInquiryList item = listdata.get(position);
		if (item.getTitle()==null) {
			item.setTitle("");
		}
		if (item.getRealname()==null) {
			item.setRealname("");
		}
		vh.title.setText(item.getTitle()+"		相似度："+item.getSimilarity());
		vh.author.setText(item.getRealname());
//		vh.iv.setTag(item.getPic_url());
//		ImageListener listener = VolleyBasic.getInstance((Activity)mContext).
//				getImageListener(vh.iv, R.drawable.ic_menu_rotate, R.drawable.ic_menu_rotate,item.getPic_url());
//		mImageLoader.get(item.getPic_url(), listener);
		Glide.with(mContext).load(item.getPic_url()+ AppUtil.picWidthUrl)
		.placeholder(R.drawable.ic_menu_rotate)
		.error(R.drawable.ic_menu_rotate).into(vh.iv);
		
		return convertView; 
	}

	class ViewHolder {
		TextView title, author;
		ImageView iv, icon;

	}
}
